-- card: 6294 from stack: in -- bmap block id: 6531 -- flags: 0000 -- background id: 2696 -- name: Expressions ----- HyperTalk script ----- on openCard -- put insertion point at beginning of field unlock screen select before char 1 of card field "Input" pass openCard end openCard on closeCard lock screen put empty into card field "Input" put empty into card field "Input2" pass closeCard end closeCard -- "Cleans up" a mathematical expression -- Remove illegal characters from expression -- Skips any characters specified as "allowable" -- Replace x and ÷ with what HyperCard wants function cleanExpr expr, allowable put "0123456789" into numeric put 1 into c repeat until c > the number of chars in expr put char c of expr into ch if ch is in allowable then add 1 to c else if ch is in " 0123456789.+-*x/÷^()" then if ch = "x" then put "*" into char c of expr else if ch = "÷" then put "/" into char c of expr end if add 1 to c else -- invalid character: delete it delete char c of expr end if end if end repeat if expr is empty then return 0 else return expr end cleanExpr -- Compare two expressions of one variable (x) -- Returns true if they are equivalent function equivalent expr1, expr2 put cleanExpr(expr1,"x") into expr1 put cleanExpr(expr2,"x") into expr2 put true into match -- check twice to make sure we don't get a fluke match repeat 2 times put random(999) into x if the value of expr1 ≠ the value of expr2 then put false into match end repeat return match end equivalent -- part 1 (field) -- low flags: 01 -- high flags: 0000 -- rect: left=23 top=65 right=106 bottom=245 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 14 -- style flags: 0 -- line height: 18 -- part name: -- part 3 (field) -- low flags: 02 -- high flags: 0002 -- rect: left=66 top=116 right=134 bottom=196 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Input ----- HyperTalk script ----- on returnInField if the value of cleanExpr(me,"") is 35.70 then rightSound else wrongSound select line 1 of me end if end returnInField -- part 4 (field) -- low flags: 00 -- high flags: 0000 -- rect: left=26 top=165 right=206 bottom=248 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 14 -- style flags: 0 -- line height: 18 -- part name: -- part 5 (field) -- low flags: 00 -- high flags: 0000 -- rect: left=43 top=227 right=245 bottom=216 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: -- part 7 (field) -- low flags: 02 -- high flags: 0000 -- rect: left=69 top=251 right=269 bottom=244 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Input2 ----- HyperTalk script ----- on returnInField if equivalent(me, "3*x + 2*(12*x + 4)") then rightSound else wrongSound select line 1 of me end if end returnInField -- part 8 (field) -- low flags: 00 -- high flags: 0000 -- rect: left=43 top=251 right=269 bottom=70 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: -- part 9 (button) -- low flags: 00 -- high flags: 2001 -- rect: left=490 top=320 right=342 bottom=512 -- title width / last selected line: 0 -- icon id / first selected line: 26635 / 26635 -- text alignment: 1 -- font id: 0 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: ----- HyperTalk script ----- on mouseUp info end mouseUp -- part 10 (field) -- low flags: 81 -- high flags: 2004 -- rect: left=267 top=83 right=287 bottom=504 -- title width / last selected line: 0 -- icon id / first selected line: 0 / 0 -- text alignment: 0 -- font id: 3 -- text size: 12 -- style flags: 0 -- line height: 16 -- part name: Info ----- HyperTalk script ----- on mouseUp info end mouseUp -- part contents for card part 1 ----- text ----- A $42 shirt is on sale for 15% off. What is the new price? -- part contents for card part 4 ----- text ----- Enter another form of the following equation. -- part contents for card part 5 ----- text ----- y = 3*x + 2*(12x + 4) -- part contents for card part 8 ----- text ----- y = -- part contents for card part 10 ----- text ----- Note that you can type ANY expression for the shirt price: 35.7 42 - .15 * 42 35 + .7 And you can type ANY equivalent equation. This is because the answers are evaluated numerically before any matching is done. (See the scripts for details.)